package com.disdr.utils;

import cn.hutool.core.lang.Validator;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class 博洋行书 {

    public static void main(String[] args) throws IOException {
        //背景图片（默认是黑色）
        BufferedImage bg = new BufferedImage(900, 800, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = (Graphics2D) bg.getGraphics();
        g2.setColor(Color.RED); // 设置背景颜色
        g2.fillRect(0, 0, 1200, 1500);// 填充整张图片(其实就是设置背景颜色)

        int x = 0;
        int y = 130;
        int t = 0;
        String str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼-=:杨林";
        for(String key : str.split("")){
            if(Validator.isNumber(key)){
                if(t==0){
                    t=1;
                    x=0;
                    y+=55;
                }
                签名抠图.签名抠图(bg,80+(x*35),y,1, getImg(key));
            }else if(Validator.isUpperCase(key)){
                if(t==1){
                    t=2;
                    x=0;
                    y+=55;
                }
                签名抠图.签名抠图(bg,80+(x*45),y,1, getImg(key));
            }else if(Validator.isChinese(key)){
                if(t==2){
                    t=3;
                    x=0;
                    y+=55;
                }
                签名抠图.签名抠图(bg,80+(x*55),y,1, getImg(key));
            }else if("-".equals(key)){
                if(t==3){
                    t=4;
                    x=0;
                    y+=55;
                }
                签名抠图.签名抠图(bg,80+(x*25),y,1, getImg(key));
            }else if(":".equals(key)){
                签名抠图.签名抠图(bg,80+(25+15),y,1, getImg(key));
            }else if("=".equals(key)){
                签名抠图.签名抠图(bg,80+(50+35),y,1, getImg(key));
            }
            x++;
            if(x%10==0){
                x=0;
                y+=55;
            }
        }
        ImageIO.write(bg, "jpg", new FileOutputStream("D:\\user\\Desktop\\抠图.jpg"));
    }

    public static BufferedImage getImg(String key) throws IOException {
        File file = new File("src\\main\\resources\\templates\\博洋行书.png");
        BufferedImage bi = ImageIO.read(file);
        Integer[] obj = map.get(key);
        return bi.getSubimage(obj[0],obj[1],obj[2],obj[3]);
    }

    static Map<String,Integer[]> map = new HashMap<>();

    static {
        map.put("0", new Integer[]{0,1,86,80});
        map.put("1", new Integer[]{86,1,86,80});
        map.put("2", new Integer[]{172,1,86,80});
        map.put("3", new Integer[]{258,1,86,80});
        map.put("4", new Integer[]{344,1,86,80});
        map.put("5", new Integer[]{430,1,86,80});
        map.put("6", new Integer[]{515,1,86,80});
        map.put("7", new Integer[]{601,1,86,80});
        map.put("8", new Integer[]{687,1,86,80});
        map.put("9", new Integer[]{773,1,86,80});
        map.put("A", new Integer[]{0,81,86,80});
        map.put("B", new Integer[]{86,81,86,80});
        map.put("C", new Integer[]{172,81,86,80});
        map.put("D", new Integer[]{258,81,86,80});
        map.put("E", new Integer[]{344,81,86,80});
        map.put("F", new Integer[]{430,81,86,80});
        map.put("G", new Integer[]{515,81,86,80});
        map.put("H", new Integer[]{601,81,86,80});
        map.put("I", new Integer[]{687,81,86,80});
        map.put("J", new Integer[]{773,81,86,80});
        map.put("K", new Integer[]{0,161,86,80});
        map.put("L", new Integer[]{86,161,86,80});
        map.put("M", new Integer[]{172,161,86,80});
        map.put("N", new Integer[]{258,161,86,80});
        map.put("O", new Integer[]{344,161,86,80});
        map.put("P", new Integer[]{430,161,86,80});
        map.put("Q", new Integer[]{515,161,86,80});
        map.put("R", new Integer[]{601,161,86,80});
        map.put("S", new Integer[]{687,161,86,80});
        map.put("T", new Integer[]{773,161,86,80});
        map.put("U", new Integer[]{0,241,86,80});
        map.put("V", new Integer[]{86,241,86,80});
        map.put("W", new Integer[]{172,241,86,80});
        map.put("X", new Integer[]{258,241,86,80});
        map.put("Y", new Integer[]{344,241,86,80});
        map.put("Z", new Integer[]{430,241,86,80});
        map.put("京", new Integer[]{0,321,86,80});
        map.put("津", new Integer[]{86,321,86,80});
        map.put("沪", new Integer[]{172,321,86,80});
        map.put("渝", new Integer[]{258,321,86,80});
        map.put("冀", new Integer[]{344,321,86,80});
        map.put("豫", new Integer[]{430,321,86,80});
        map.put("云", new Integer[]{515,321,86,80});
        map.put("辽", new Integer[]{601,321,86,80});
        map.put("黑", new Integer[]{687,321,86,80});
        map.put("湘", new Integer[]{773,321,86,80});
        map.put("皖", new Integer[]{0,401,86,80});
        map.put("鲁", new Integer[]{86,401,86,80});
        map.put("新", new Integer[]{172,401,86,80});
        map.put("苏", new Integer[]{258,401,86,80});
        map.put("浙", new Integer[]{344,401,86,80});
        map.put("赣", new Integer[]{430,401,86,80});
        map.put("鄂", new Integer[]{515,401,86,80});
        map.put("桂", new Integer[]{601,401,86,80});
        map.put("甘", new Integer[]{687,401,86,80});
        map.put("晋", new Integer[]{773,401,86,80});
        map.put("蒙", new Integer[]{0,481,86,80});
        map.put("陕", new Integer[]{86,481,86,80});
        map.put("吉", new Integer[]{172,481,86,80});
        map.put("闽", new Integer[]{258,481,86,80});
        map.put("贵", new Integer[]{344,481,86,80});
        map.put("粤", new Integer[]{430,481,86,80});
        map.put("青", new Integer[]{515,481,86,80});
        map.put("藏", new Integer[]{601,481,86,80});
        map.put("川", new Integer[]{687,481,86,80});
        map.put("宁", new Integer[]{773,481,86,80});
        map.put("琼", new Integer[]{0,561,86,80});
        map.put("-", new Integer[]{0,641,86,80});
        map.put("=", new Integer[]{86,641,86,80});
        map.put(":", new Integer[]{172,641,86,80});
        map.put("杨", new Integer[]{0,721,86,80});
        map.put("林", new Integer[]{86,721,86,80});

    }
}
